<?php
namespace app\cms\loglic;

class Detail
{
    public function fields($data=[])
    {
        $action = DcEmpty($data['info_action'],'index');
        
        $categorys = DcTermCheck([
            'module' => ['eq','cms'],
            'action' => ['eq',$action],
        ]);
        
        $infoType = cmsTypeOption($action);
        
        $fieldsLeft = [
            'div1' => [
                'order'           => 0,
                'type'            => 'html',
                'value'           => '<div class="row"><div class="col-12 col-md-3 col-lg-2 col-xl-1 order-1">',
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'info_action' => [
                'order'           => 0,
                'type'            => 'hidden',
                'value'           => $action,
            ],
            'info_controll' => [
                'order'           => 0,
                'type'            => 'hidden',
                'value'           => 'detail',
            ],
            'info_user_id' => [
                'order'           => 0,
                'type'            => 'hidden',
                'value'           => DcUserCurrentGetId(),
            ],
            'info_id' => [
                'order'           => 2,
                'type'            => 'hidden',
                'value'           => $data['info_id'],
                'data-title'      => lang('cms_id'),
                'data-filter'     => false,
                'data-visible'    => true,
                'data-sortable'   => true,
                'data-width'      => '80',
                'data-width-unit' => 'px',
            ],
            'category_id' => [
                'order'             => 0,
                'type'              => 'checkbox',
                'value'             => $data['category_id'],
                'option'            => $categorys,
                'title'             => lang('cms_category'),
                'class_right_check' => 'form-check py-1 text-truncate',
                'data-filter'       => true,
                'data-type'         => 'select',
                'data-option'       => cmsDataOption($categorys),
                'data-class'        => 'text-wrap',
            ],
            'cms_category' => [
                'order'             => 6,
                'data-title'        => lang('cms_category'),
                'data-visible'      => true,
            ],
            'info_type' => [
                'order'           => 15,
                'type'            => 'radio',
                'value'           => DcEmpty($data['info_type'],$action),
                'option'          => $infoType,
                'title'           => lang('cms_type'),
                'data-title'      => lang('cms_type'),
                'data-filter'     => true,
                'data-visible'    => true,
                'data-type'       => 'select',
                'data-option'     => array_merge([0=>'---'],$infoType),
            ],
            'info_status' => [
                'order'           => 13,
                'type'            => 'radio',
                'value'           => DcEmpty($data['info_status'],'normal'),
                'option'          => model('common/Attr','loglic')->statusOption(),
                'title'           => lang('cms_status'),
                'data-filter'     => true,
                'data-visible'    => false,
            ],
            'info_status_text' => [
                'order'           => 14,
                'data-title'      => lang('cms_status'),
                'data-visible'    => true,
            ],
            'cms_color'       => [
                'order'           => 16,
                'type'            => 'radio',
                'value'           => DcEmpty($data['cms_color'],'text-dark'),
                'option'          => [
                    'text-dark'      => 'text-dark',
                    'text-danger'    => 'text-danger',
                    'text-success'   => 'text-success',
                    'text-primary'   => 'text-primary',
                    'text-info'      => 'text-info',
                    'text-secondary' => 'text-secondary',
                    'text-muted'     => 'text-muted',
                    'text-light'     => 'text-light',
                ],
                'title'              => lang('cms_color'),
            ],
            'cms_attr' => [
                'order'             => 11,
                'type'              => 'checkbox',
                'value'             => cmsAttrValue($data),
                'option'            => cmsAttrOption(),
                'class_right_check' => 'form-check py-1 text-truncate',
                'data-filter'       => true,
                'data-type'         => 'select',
                'data-option'       => array_merge([0=>'---'],cmsAttrOption()),
            ],
            'div2' => [
                'order'           => 1,
                'type'            => 'html',
                'value'           => '</div><div class="col-12 col-md-9 col-lg-10 col-xl-11 order-2">',
            ],
        ];
        if(!$categorys){
            unset($fieldsLeft['category_id']);
            unset($fieldsLeft['cms_category']);
        }
        if(!$infoType){
            unset($fieldsLeft['info_type']);
        }
        
        $fieldsRight = [
            'info_name' => [
                'order'           => 3,
                'type'            => 'text',
                'value'           => $data['info_name'],
                'title'           => lang('cms_name'),
                'placeholder'     => lang('cmsTipsInfoNmae'),
                'class'           => 'form-group col-md-6',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => true,
                'data-align'      => 'left',
                'data-width'      => '30',
                'data-width-unit' => '%',
            ],
            'info_slug' => [
                'order'           => 4,
                'type'            => 'text',
                'value'           => $data['info_slug'],
                'title'           => lang('cms_slug'),
                'class'           => 'form-group col-md-6',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'cms_cover' => [
                'order'           => 5,
                'type'            => 'image',
                'value'           => $data['cms_cover'],
                'title'           => lang('cms_cover'),
                'class'           => 'form-group col-md-6',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'cms_slide' => [
                'order'           => 6,
                'type'            => 'image',
                'value'           => $data['cms_slide'],
                'title'           => lang('cms_slide'),
                'class'           => 'form-group col-md-6',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'info_content' => [
                'order'           => 9,
                'type'            => 'editor',
                'value'           => $data['info_content'],
                'title'           => lang('cms_content'),
                'rows'            => 35,
                'height'          => '35rem',
                'class'           => 'form-group col-12',
                'class_left'      => 'w-100 d-none',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'tag_name'  => [
                'order'           => 7,
                'type'            =>'tags',
                'value'           => implode(',',$data['tag_name']),
                'option'          => cmsTags($action,12),
                'title'           => lang('cms_tag'),
                'class'           => 'form-group col-12',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'class_tags'      => 'form-text pt-1',
                'class_tags_list' => 'text-purple mr-2',
            ],
            'info_excerpt' => [
                'order'           => 8,
                'type'            => 'textarea',
                'value'           => $data['info_excerpt'],
                'rows'            => 3,
                'class'           => 'form-group col-12',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'class_right_control' => 'form-control form-control-sm text-muted',
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            /*'info_description' => [
                'order'           => 27,
                'type'            => 'textarea',
                'value'           => $data['info_description'],
                'rows'            => 3,
                'title'           => lang('cms_seo_description'),
                'class'           => 'form-group col-12',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => false,
            ],*/
            'info_title' => [
                'order'           => 25,
                'type'            => 'text',
                'value'           => $data['info_title'],
                'title'           => lang('cms_seo_title'),
                'class'           => 'form-group col-md-6',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'info_keywords' => [
                'order'           => 26,
                'type'            => 'text',
                'value'           => $data['info_keywords'],
                'title'           => lang('cms_seo_keywords'),
                'class'           => 'form-group col-md-6',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'info_order' => [
                'order'           => 17,
                'type'            => 'number',
                'value'           => intval($data['info_order']),
                'class'           => 'form-group col-md-1',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => true,
                'data-sortable'   => true,
                //'data-width'      => 80,
            ],
            'info_views' => [
                'order'           => 18,
                'type'            => 'number',
                'value'           => intval($data['info_views']),
                'class'           => 'form-group col-md-1',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => true,
                'data-sortable'   => true,
                //'data-width'      => 80,
            ],
            'info_hits' => [
                'order'           => 19,
                'type'            => 'number',
                'value'           => intval($data['info_hits']),
                'class'           => 'form-group col-md-1',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => true,
                'data-sortable'   => true,
                //'data-width'      => 80,
            ],
            'cms_up' => [
                'order'           => 20,
                'type'            => 'number',
                'value'           => intval($data['cms_up']),
                'title'           => lang('cms_up'),
                'class'           => 'form-group col-md-1',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-title'      => lang('cms_up'),
                'data-filter'     => false,
                'data-visible'    => true,
                'data-sortable'   => true,
                //'data-width'      => 80,
            ],
            'cms_down' => [
                'order'           => 21,
                'type'            => 'number',
                'value'           => intval($data['cms_down']),
                'title'           => lang('cms_down'),
                'class'           => 'form-group col-md-1',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-title'      => lang('cms_down'),
                'data-filter'     => false,
                'data-visible'    => true,
                'data-sortable'   => true,
                //'data-width'      => 80,
            ],
            'cms_letter' => [
                'order'           => 22,
                'type'            => 'text',
                'value'           => $data['cms_letter'],
                'title'           => lang('cms_letter'),
                'placeholder'     => lang('cmsTipsCmsLetter'),
                'class'           => 'form-group col-md-1',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-title'      => lang('cms_letter'),
                'data-filter'     => false,
                'data-visible'    => true,
                'data-sortable'   => true,
                //'data-width'      => 80,
            ],
            'cms_tpl' => [
                'order'           => 23,
                'type'            => 'text',
                'value'           => $data['cms_tpl'],
                'title'           => lang('cms_tpl'),
                'class'           => 'form-group col-md-3',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'placeholder'     => lang('cmsTipsCmsTpl'),
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'cms_referer' => [
                'order'           => 24,
                'type'            => 'text',
                'value'           => $data['cms_referer'],
                'title'           => lang('cms_referer'),
                'placeholder'     => lang('cmsTipsCmsReferer'),
                'class'           => 'form-group col-md-3',
                'class_left'      => 'w-100',
                'class_right'     => 'w-100',
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'info_update_time' => [
                'order'           => 510,
                'data-visible'    => true,
                'data-sortable'   => true,
                'data-width'      => 120,
            ],
        ];
        //自定义字段
        if($customs = cmsMetaList('detail', $action)){
            $fieldsRight = array_merge($fieldsRight, DcFields($customs, $data));
        }
        //格式化右栏
        $fieldsRight = adminFormRow($fieldsRight,'col-md-6');
        //右伴布局结尾
        array_push($fieldsRight,['type'=>'html','value'=>'</div></div>']);
        //返回所有表单字段
        return array_merge($fieldsLeft,$fieldsRight);
    }
}